<template>
  <view class="search-bar">
    <input type="text" placeholder="按用户ID/昵称" v-model="searchQuery" class="search-input" />
    <button @click="search" class="search-button">
      <uni-icons type="search" size="30"></uni-icons>
    </button>
  </view>
</template>

<script setup lang="ts">
import { ref, defineEmits } from 'vue'

const emit = defineEmits<{
  (e: 'search', query: string): void
}>()

const searchQuery = ref('')

const search = () => {
  emit('search', searchQuery.value)
  console.log(`Search query: ${searchQuery.value}`)
}
</script>

<style scoped>
.search-bar {
  display: flex;
  align-items: center;
  position: relative;
}

.search-bar input {
  flex: 1;
  padding: 5rpx;
  border: none;
  border-radius: 4rpx;
  padding-right: 40rpx;
}

.search-bar input::placeholder {
  color: #ccc;
  opacity: 1;
}

.search-input {
  height: 40rpx;
  margin: 2rpx;
}

.search-button {
  position: absolute;
  right: 5rpx;
  background-color: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
}

.search-button uni-icons {
  color: #007bff;
}
</style>
